#ifndef PLAYER_H
#define PLAYER_H
#include<anmation.h>
#include "hearts.h"
#include "maploader.h"
#include "nextmaploder.h"
#include "specialteam.h"
class Player : public QObject ,public Specialteam
{
Q_OBJECT
private:

nextmaploder*nextmap=nullptr;
maploader* map=nullptr;
int applenumber=0;
int winapplenumber=1;
bool m_canDoubleJump = false;  // 标记是否允许二段跳
QTimer m_doubleJumpTimer;
QTimer* m_walkTimer = nullptr;
QString isrunning="notrunning";
anmation*myanmation=nullptr;
QVector<QPixmap> m_frames;

qreal spawnx=0,spawny=0;
    qreal velocity_y=0,velocity_x=0;
    qreal x=0,y=0;
    int life=2;
    bool is_ground=true;
    //bool rightcollision=false,leftcollision=false,upcollision=false,downcollision=false;//记录角色上下左右的碰撞情况
    bool canjump=true;
    //设定血量，位置，位移速度,是否在地面上的状态。
    bool m_isInvincible = false; // 是否处于无敌状态
    QTimer* m_invincibleTimer;
public:
hearts*heart=nullptr;
    hearts *heart2=nullptr;
    Player();
    Player(qreal spawnx,qreal spawny,maploader*map=nullptr/*,nextmaploder*nextmap=nullptr*/);
public slots:
    void moveleft();
    void moveright();
    void jump();//设置角色跳跃，移动。
    void stop();
    void endInvincibility();
    void died();
public:
   void  startInvincibility();
    void collisionwithground(QGraphicsItem *collisionItem);//处理角色和可碰撞的地形类碰撞
    void collisionwithenemy();
    void collisionwithcodeitem();
   void collisionwithtrapground(QGraphicsItem *collisionItem);
    void collisionwithapple();
    void update();//处理角色状态的更新逻辑
    void gravity();//模拟重力
    void collisionisground();//进行碰撞检测，调用相应的碰撞函数
    void updatepoint();//处理更新坐标的相关问题
    qreal sweptTest(QRectF currentaabb, QRectF otheraabb,qreal&timex,qreal&timey);
    void restart();
    void setwinapplenumber(int number);
signals:
    void gameover();
    void gamewin();
    public:
    anmation*m_leftrunAnimation;
    anmation* m_runAnimation; // 行走动画
    anmation* m_jumpAnimation;// 跳跃动画
    anmation* m_doublejumpAnimation;
    anmation*m_hitAnimation;
    anmation*m_fallAnimation;
    anmation*m_IdleAnimation;
public:
    void startrun();
    void startstop();
    void startleftrun();
    void startjump();
    void startdoublejump();
};

#endif // PLAYER_H
